package com.shushan.lockscreen;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;

/**
 * @ClassName: TelephonyStateReceiver
 * @Desciption: //监听悬浮窗开启后的通话状态
 * @author: zhangshihao
 * @date: 2018-03-23
 */
public class TelephonyStateReceiver extends BroadcastReceiver {

    private static final String TAG = "TelephonyStateReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        if(!LockScreenWindowManager.isLockScreenAvailable()){
            return;
        }
        TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        int callState = telephonyManager.getCallState();
        Log.i(TAG,"callState = "+String.valueOf(callState));
        if(callState == TelephonyManager.CALL_STATE_RINGING){
            LockScreenWindowManager.removeLockFloatWindow(context);
        }else if(callState == TelephonyManager.CALL_STATE_IDLE){
            LockScreenWindowManager.setLockScreenAvailable(false);
            LockScreenWindowManager.createLockFloatWindow(context);
        }
    }

}
